package businessLogic.facade;

import businessLogic.service.ProfesorService;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import vo.IValueObject;
import vo.ProfesorVO;

/**
 *
 * @author Alexander
 */
public class ProfesorFacade extends Facade {

    public ProfesorFacade() {
        setService(new ProfesorService());
    }

    @Override
    protected boolean exist(IValueObject vo) {
        if (super.find(((ProfesorVO) vo).getId()) == null) {
            return false;
        } else {
            return true;
        }
    }

    public ProfesorVO finByName(String nombre, String apellido) {
        EntityManagerFactory emf = null;
        EntityManager em = null;
        ProfesorVO profeVO = null;
        try {
            emf = Persistence.createEntityManagerFactory("StunnicusPU");
            em = emf.createEntityManager();
            profeVO = ((ProfesorService) getService()).findByName(nombre, apellido, em);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
            em.close();
            return profeVO;
        }

    }
}
